package com.office.file.collect.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.office.common.utils.SecurityUtils;
import com.office.file.message.domain.FileInfo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.office.common.annotation.Log;
import com.office.common.core.controller.BaseController;
import com.office.common.core.domain.AjaxResult;
import com.office.common.enums.BusinessType;
import com.office.file.collect.domain.FileFavorite;
import com.office.file.collect.service.IFileFavoriteService;
import com.office.common.utils.poi.ExcelUtil;
import com.office.common.core.page.TableDataInfo;

/**
 * 用户收藏文件Controller
 * 
 * @author ruoyi
 * @date 2025-07-14
 */
@RestController
@RequestMapping("/file/fileCollect")
public class FileFavoriteController extends BaseController
{
    @Autowired
    private IFileFavoriteService fileFavoriteService;

    /**
     * 查询用户收藏文件列表
     */
    @GetMapping("/list")
    public TableDataInfo list(FileInfo fileFavorite)
    {
        startPage();
        fileFavorite.setUserId(SecurityUtils.getUserId());
        List<FileInfo> list = fileFavoriteService.selectFileFavoriteList(fileFavorite);
        return getDataTable(list);
    }


    /**
     * 获取用户收藏文件详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(fileFavoriteService.selectFileFavoriteById(id));
    }

    /**
     * 新增用户收藏文件
     */
    @Log(title = "用户收藏文件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FileFavorite fileFavorite)
    {
        return toAjax(fileFavoriteService.insertFileFavorite(fileFavorite));
    }

    /**
     * 修改用户收藏文件
     */
    @Log(title = "用户收藏文件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FileFavorite fileFavorite)
    {
        return toAjax(fileFavoriteService.updateFileFavorite(fileFavorite));
    }

    /**
     * 删除用户收藏文件
     */
    @Log(title = "用户收藏文件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fileFavoriteService.deleteFileFavoriteByIds(ids));
    }
    /**
     * 使用登录userId获取收藏的file
     */
    @GetMapping("/collectFile")
    public TableDataInfo fileList(FileInfo fileFavorite)
    {
        startPage();
        fileFavorite.setUserId(SecurityUtils.getUserId());
        List<FileInfo> list = fileFavoriteService.selectList(fileFavorite);
        return getDataTable(list);
    }

}
